package com.ssyu.examination.conmmon;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ssyu.examination.system.entity.SystemEntiy;

public class App {
	public static int getOperateId(HttpServletRequest request,
			HttpServletResponse response) {
		try {
			Object obj = request.getSession().getAttribute("systemEntiy");
			if (obj == null) {
				request.setAttribute("flag", "fail");
				request.getRequestDispatcher("/login.jsp").forward(request,
						response);
			} else {
				SystemEntiy systemEntiy = (SystemEntiy) obj;
				int operateId = systemEntiy.getId();
				return operateId;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		throw new RuntimeException("未知错误，获取操作者id失败！");
	}

	public static String getSystemCode(HttpServletRequest request,
			HttpServletResponse response) {
		try {
			Object obj = request.getSession().getAttribute("systemEntiy");
			if (obj == null) {
				request.setAttribute("msg", "长时间没有操作，请重新登录！");
				request.getRequestDispatcher("/login.jsp").forward(request,
						response);
			} else {
				SystemEntiy system = (SystemEntiy) obj;
				String code = system.getCode();
				return code;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		throw new RuntimeException("未知错误，获取code失败！");
	}
}
